
var Singleton = function (name) {
    this.name = name
}

Singleton.prototype.getName = function() {
    console.log(this.name);
}

Singleton.getInstance = (function(name) {
    var instance = null 
    return function() {
        if(!instance) {
            instance = new Singleton(name)
        }
        return instance
    }
})()

var a = Singleton.getInstance("test1")
var b = Singleton.getInstance("test2")

console.log(a === b); // true